package top.mccat.common.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.mccat.common.core.domain.bk.BkBase;
import top.mccat.common.mapper.bk.BkBaseMapper;
import top.mccat.common.mapper.bk.BkProductBaseMapper;
import top.mccat.common.service.IBkBaseService;

import java.util.List;

/**
 * 仓库管理Service业务层处理
 * 
 * @author Raven
 * @date 2023-01-09
 */
@Service
public class BkBaseServiceImpl implements IBkBaseService 
{
    @Autowired
    private BkBaseMapper bkBaseMapper;
    @Autowired
    private BkProductBaseMapper bkProductBaseMapper;

    /**
     * 查询仓库管理
     * 
     * @param id 仓库管理主键
     * @return 仓库管理
     */
    @Override
    public BkBase selectBkBaseById(Integer id)
    {
        return bkBaseMapper.selectBkBaseById(id);
    }

    /**
     * 查询仓库管理列表
     * 
     * @param bkBase 仓库管理
     * @return 仓库管理
     */
    @Override
    public List<BkBase> selectBkBaseList(BkBase bkBase)
    {
        return bkBaseMapper.selectBkBaseList(bkBase);
    }

    /**
     * 新增仓库管理
     * 
     * @param bkBase 仓库管理
     * @return 结果
     */
    @Override
    @Transactional
    public int insertBkBase(BkBase bkBase)
    {
        int row = bkBaseMapper.insertBkBase(bkBase);
        bkProductBaseMapper.insertBkProductBase(bkBase);
        return row;
    }

    /**
     * 修改仓库管理
     * 
     * @param bkBase 仓库管理
     * @return 结果
     */
    @Override
    @Transactional
    public int updateBkBase(BkBase bkBase)
    {
        int row = bkBaseMapper.updateBkBase(bkBase);
        //先删除关联
        bkProductBaseMapper.deleteBkProductBaseByBaseId(bkBase.getId());
        //再更新关联
        bkProductBaseMapper.insertBkProductBase(bkBase);
        return row;
    }

    /**
     * 批量删除仓库管理
     * 
     * @param ids 需要删除的仓库管理主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteBkBaseByIds(Integer[] ids)
    {
        int row = bkBaseMapper.deleteBkBaseByIds(ids);
        bkProductBaseMapper.deleteBkProductBaseByBaseIds(ids);
        return row;
    }

    /**
     * 删除仓库管理信息
     * 
     * @param id 仓库管理主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteBkBaseById(Integer id)
    {
        int row = bkBaseMapper.deleteBkBaseById(id);
        bkProductBaseMapper.deleteBkProductBaseByBaseId(id);
        return row;
    }
}
